#!/bin/bash


export PATH=/opt/bind/bin:/bin:/usr/bin


print_usage()
{
echo -e "
	Usage: $(basename $0) zonename master1/master2 ...
"
}


if [ $# -ne 2 ]; then print_usage; exit 1; fi

zone=$1
masters=$(echo $2 | sed -e 's/\// /g')

if [ "X$(uname -s)" == "XSunOS" ]; then 
    GREP="/usr/xpg4/bin/grep"
else
    GREP="/bin/grep"
fi

. /etc/named/IT_DNS_SERVERS

for itmaster in $(echo $DNS_PRIMARY_MASTER $DNS_PSEUDO_MASTERS); do
    for remote in $(echo $masters); do
	    echo -e "  Verifying $itmaster transfer zone \"${zone}\" from $remote... \c"
    	echo "dig @${remote} -t axfr $zone +tcp +short 2>/dev/null" \
			| ssh $itmaster bash 2>/dev/null | head -1 | $GREP -q "^[A-z]"
	    if [ $? -eq 0 ]; then echo Succeeds.; else echo Fails.; fi
	    sleep 2
    done
done
